package com.example.myapplication.mySQL;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class mySQL extends SQLiteOpenHelper {


    public mySQL(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }
    //首次创建初始化
    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        //创建sql语句
        String sql="create table if not exists shoucang(_id integer primary key autoincrement,img integer,name text,title text,date text,count integer);";
        //执行sql
        sqLiteDatabase.execSQL(sql);
    }
//检测版本更新触发
    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        //当数据库写错修改时升级版本要删除表
        String sql = "drop table if exists shoucang;";
        sqLiteDatabase.execSQL(sql);
        onCreate(sqLiteDatabase);
    }

}
